home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 550 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.2 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: hickeyr@ibm.net (Rich Hickey)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Proposal: Reconcile Inheritance and Inlining
  5. Date: 26 Feb 1996 09:35:55 PST
  6. Organization: -
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4gqika$j00@news-s01.ny.us.ibm.net>
  9. References: <4gkas9$4o84@news-s01.ny.us.ibm.net>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 25 Feb 1996 20:59:54 GMT
  12. X-Newsreader: NeoLogic News for OS/2 [version: 4.2]
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMTHvkky4NqrwXLNJAQFr6wH/YsjJ8/uMSK0WlfW1sidzE+nLC7Ny41aW
  15.     o9Z58PAKHs15Ojs93dq+VMDIla6N8U2YmozkjrMuMaI81K8P5ZuAEA==
  16.     =+cCt
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. In message <4gkscd$8rl@news.BelWue.DE> - 
  20. kuehl@uzwil.informatik.uni-konstanz.de (Dietmar Kuehl) writes:
  21. :>
  22. :>Hi,
  23. :>
  24. :>Rich Hickey (hickeyr@ibm.net) wrote:
  25. :>[Explanation of the proposal removed]
  26. :>
  27. :>: class B{
  28. :>: public:
  29. :>:    virtual int foo()const=0;
  30. :>:    //...
  31. :>: };
  32. :>
  33. :>: explicit class D:public B{
  34. :>: public:
  35. :>:   int foo()const{return data;}
  36. :>:   //...
  37. :>: private:
  38. :>:   int data;
  39. :>: };
  40. :>
  41. :>: void fred(const D &d)
  42. :>:    {
  43. :>:    d.foo();  //as if d.D::foo(); - inlined
  44. :>:    }
  45. :>
  46. :>: void ethel(const B &b)
  47. :>:   {
  48. :>:   b.foo();    //even if b is a D, virtual function call (as always)
  49. :>:   }
  50. :>
  51. :>
  52. :>: It cannot be otherwise accomplished in the language, i.e. it requires an extension.
  53. :>
  54. :>I think it is easy to accomplish the thing you want to do in the language:
  55. :>
  56. :>  class E: public B {
  57. :>  public:
  58. :>    int foo_inline() const { return data; }
  59. :>    int foo() const        { foo_inline(); }
  60. :>  private:
  61. :>    int data;
  62. :>  };
  63. :>
  64. :>  void foo(E const &e)
  65. :>  {
  66. :>    e.foo_inline(); // inline. Note that you know exactly the type of 'e'
  67. :>    e.foo();        // virtual as ever
  68. :>  }
  69. :>
  70. :>Although I agree with you that your proposal is nicer to use, your
  71. :>claim that it cannot be implemented in the language is wrong...
  72.  
  73. What your are suggesting does not accomplish the same thing, i.e. it does 
  74. not, in the language, accomplish an inline call to a virtual function called 
  75. via a reference or pointer.
  76.  
  77. void fred(const D &d)
  78.    {
  79.    d.foo();  //as if d.D::foo(); - inlined
  80.    }
  81.  
  82. I want to avoid wrapper classes, duplicate functions etc. The technique you 
  83. are suggesting has always been available yet has seen little use (that I am 
  84. aware of). It is much more than a matter of transparency or convenience. 
  85. Developers may not consider your solution viable for a number of 
  86. possible reasons.
  87.  
  88. Some of the differences are:
  89.  
  90. Double the number of functions in the concrete class, with the accompanying 
  91. confusion and maintenance headaches.
  92.  
  93. An inability to easily change code that uses the base to use the derived, or 
  94. vice-versa, due to the different names.
  95.  
  96. Thus, in spite of your technique having been available to them, most 
  97. developers still consider hierarchy vs. inlining as an either-or choice.
  98.  
  99. Rich
  100. ---
  101. [ To submit articles: Try just posting with your newsreader.  If that fails,
  102.                       use mailto:std-c++@ncar.ucar.edu
  103.   FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  104.   Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  105.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  106. ]
  107.